#include <X11/XF86keysym.h>

static int showsystray                    = 0;          /* 是否显示托盘栏 */
static const unsigned int borderpx        = 2;          /* 窗口边框大小 */
static const unsigned int systraypinning  = 0;          /* 托盘跟随的显示器 0代表不指定显示器 */
static const unsigned int systrayspacing  = 1;          /* 托盘间距 */
static const unsigned int systrayspadding = 1;          /* 托盘和状态栏的间隙 */
static int gappi                          = 8;         /* 窗口与窗口 缝隙大小 */
static int gappo                          = 8;         /* 窗口与边缘 缝隙大小 */
static const int _gappo                   = 8;         /* 窗口与窗口 缝隙大小 不可变 用于恢复时的默认值 */
static const int _gappi                   = 8;         /* 窗口与边缘 缝隙大小 不可变 用于恢复时的默认值 */
static const int vertpad                  = 0;          /* vertical padding of bar */
static const int sidepad                  = 0;          /* horizontal padding of bar */
static const int overviewgappi            = 24;         /* overview时 窗口与边缘 缝隙大小 */
static const int overviewgappo            = 60;         /* overview时 窗口与窗口 缝隙大小 */
static const int showbar                  = 1;          /* 是否显示状态栏 */
static const int topbar                   = 1;          /* 指定状态栏位置 0底部 1顶部 */
static const int newclientathead          = 0;          /* 定义新窗口在栈顶还是栈底 */
static const int smartgaps                = 0;          /* 1表示只有一个窗口时没有外部间隙 */
static const float mfact                  = 0.5;        /* 主工作区 大小比例 */
static const int nmaster                  = 1;          /* 主工作区 窗口数量 */
static const unsigned int snap            = 10;         /* 边缘依附宽度 */
static const unsigned int baralpha        = 0xc0;       /* 状态栏透明度 */
static const unsigned int borderalpha     = 0xdd;       /* 边框透明度 */


static const char *fonts[] = {
  "JetBrainsMono Nerd Font:style=medium:size=12",
  // "Hack NF:style=medium:size=13",
  "JetBrainsMono Nerd Font:size=10"
};
static const char *colors[][3] = {
    /* 颜色设置 ColFg, ColBg, ColBorder */
    [SchemeNorm] = {"#bbbbbb", "#333333", "#444444"},
    [SchemeSel] = {"#ffffff", "#37474F", "#42A5F5"},
    [SchemeSelGlobal] = {"#ffffff", "#37474F", "#FFC0CB"},
    [SchemeHid] = {"#dddddd", NULL, NULL},
    [SchemeSystray] = {NULL, "#7799AA", NULL},
    [SchemeUnderline] = {"#7799AA", NULL, NULL},
    [SchemeNormTag] = {"#bbbbbb", "#333333", NULL},
    [SchemeSelTag] = {"#eeeeee", "#333333", NULL},
    [SchemeBarEmpty] = {NULL, "#111111", NULL},
};

static const unsigned int alphas[][3] = {
    /* 透明度设置 ColFg, ColBg, ColBorder */
    [SchemeNorm] = {OPAQUE, baralpha, borderalpha},
    [SchemeSel] = {OPAQUE, baralpha, borderalpha},
    [SchemeSelGlobal] = {OPAQUE, baralpha, borderalpha},
    [SchemeNormTag] = {OPAQUE, baralpha, borderalpha},
    [SchemeSelTag] = {OPAQUE, baralpha, borderalpha},
    [SchemeBarEmpty] = { 0, 0xa0a, 0},
    [SchemeStatusText] = {OPAQUE, 0x88, 0},
};


/* 自定义脚本位置 */
static const char *autostartscript = "$HOME/.scripts/autostart.sh";
// static const char *statusbarscript = "$HOME/dwmScript/statusbar/statusbar.sh";


/* 自定义 scratchpad instance */
static const char scratchpadname[] = "scratchpad";

/* 自定义tag名称 */
/* 自定义特定实例的显示状态 */
//            ﮸  ﭮ 切
// 对应的tag序号以及快捷键:   0:1  1:2  2:3  3:4  4:5  5:9  6:c  7:m  8:0  9:w
static const char *tags[] = {
  " 壹 ", " 贰 ", " 叁 ", " 肆 ", " 伍 "," 陆 ", " 柒 ", " 捌 ", " 玖 "
};

static const Rule rules[] = {
    /* class                 instance              title             tags mask
      isfloating  isglobal    isnoborder monitor */
    {"flameshot", NULL, NULL, 0, 1, 0, 0, -1},
    // {"wemeetapp", NULL, NULL, TAGMASK, 1, 1, 0, -1}, // 腾讯会议在切换tag时有诡异bug导致退出 变成global来规避该问题
    {"electron", NULL, NULL, 0, 1, 0, 0, -1},        // 浮动
    // {"netease-cloud-music", NULL, NULL, 0, 1, 0, 0, -1},        // 浮动
    /** 部分特殊class的规则 */
    {"float", NULL, NULL, 0, 1, 0, 0, -1},        // 浮动
    {"global", NULL, NULL, TAGMASK, 0, 1, 0, -1}, // 全局
    {"noborder", NULL, NULL, 0, 0, 0, 1, -1},     // 无边框
    {"FG", NULL, NULL, TAGMASK, 1, 1, 1, -1},     // 浮动 + 全局
    {"FN", NULL, NULL, 0, 1, 0, 1, -1},           // 浮动 + 无边框
    {"GN", NULL, NULL, TAGMASK, 0, 1, 1, -1},     // 全局 + 无边框
    {"FGN", NULL, NULL, TAGMASK, 1, 1, 1, -1},    // 浮动 + 全局 + 无边框
};
static const char *overviewtag = "OVERVIEW";
static const Layout overviewlayout = {"󰕮", overview};
// 󰜬
/* 自定义布局 */
static const Layout layouts[] = {
    {"󰙀", tile},      /* 主次栈 */
    {"󰍲", magicgrid}, /* 网格 */
};

#define SHCMD(cmd)                                                             \
  {                                                                            \
    .v = (const char *[]) { "/bin/sh", "-c", cmd, NULL }                       \
  }
#define MODKEY Mod4Mask
#define TAGKEYS(KEY, TAG, cmd)                                                 \
  {MODKEY, KEY, view, {.ui = 1 << TAG, .v = cmd}},                             \
      {MODKEY | ShiftMask, KEY, tag, {.ui = 1 << TAG}},                        \
      {MODKEY | ControlMask, KEY, toggleview, {.ui = 1 << TAG}},

static Key keys[] = {
    /* super +            |  切换 托盘栏显示状态 */
    {MODKEY, XK_equal, togglesystray, {0}},
    /* super tab          |  本tag内切换聚焦窗口 */
    {MODKEY, XK_Tab, focusstack, {.i = +1}},
    /* super up           |  本tag内切换聚焦窗口 */
    {MODKEY, XK_k, focusstack, {.i = -1}},
    /* super down         |  本tag内切换聚焦窗口 */
    {MODKEY, XK_j, focusstack, {.i = +1}},
    /* super left         |  聚焦到左边的tag */
    {MODKEY, XK_Left, viewtoleft, {0}},
    /* super right        |  聚焦到右边的tag */
    {MODKEY, XK_Right, viewtoright, {0}},
    /* super shift left   |  将本窗口移动到左边tag */
    {MODKEY | ShiftMask, XK_Left, tagtoleft, {0}},
    /* super shift right  |  将本窗口移动到右边tag */
    {MODKEY | ShiftMask, XK_Right, tagtoright, {0}},
    /* super a            |  显示所有tag 或 跳转到聚焦窗口的tag */
    {MODKEY, XK_a, toggleoverview, {0}},
    /* super ,            |  缩小主工作区 */
    {MODKEY, XK_comma, setmfact, {.f = -0.05}},
    /* super .            |  放大主工作区 */
    {MODKEY, XK_period, setmfact, {.f = +0.05}},
    /* super h            |  隐藏 窗口 */
    {MODKEY, XK_u, hidewin, {0}},
    /* super shift h      |  取消隐藏 窗口 */
    {MODKEY | ShiftMask, XK_u, restorewin, {0}},
    /* super shift enter  |  将当前聚焦窗口置为主窗口 */
    {MODKEY, XK_n, zoom, {0}},
    /* super t            |  开启/关闭 聚焦目标的float模式 */
    {MODKEY, XK_t, togglefloating, {0}},
    /* super shift t      |  开启/关闭 全部目标的float模式 */
    {MODKEY | ShiftMask, XK_t, toggleallfloating, {0}},
    /* super f            |  开启/关闭 全屏 */
    {MODKEY, XK_f, fullscreen, {0}},
    /* super shift f      |  开启/关闭 状态栏 */
    {MODKEY | ShiftMask, XK_f, togglebar, {0}},
    /* super e            |  改变主工作区窗口数量 (1 2中切换) */
    {MODKEY, XK_e, incnmaster, {.i = +1}},
    /* super b            |  光标移动到另一个显示器 */
    {MODKEY, XK_b, focusmon, {.i = +1}},
    /* super shift b      |  将聚焦窗口移动到另一个显示器 */
    {MODKEY | ShiftMask, XK_b, tagmon, {.i = +1}},
    /* super q            |  关闭窗口 */
    {MODKEY, XK_q, killclient, {0}},
    /* super ctrl f12     |  退出dwm */
    {MODKEY | ShiftMask, XK_q, quit, {0}},
    /* super shift space  |  切换到网格布局 */
    {MODKEY | ShiftMask, XK_space, selectlayout, {.v = &layouts[1]}},
    /* super o            |  切换 只显示一个窗口 / 全部显示 */
    {MODKEY, XK_m, showonlyorall, {0}},
    /* super ctrl up      |  窗口增大 */
    {MODKEY | ControlMask, XK_equal, setgap, {.i = -6}},
    /* super ctrl down    |  窗口减小 */
    {MODKEY | ControlMask, XK_minus, setgap, {.i = +6}},
    /* super ctrl space   |  窗口重置 */
    {MODKEY | ControlMask, XK_space, setgap, {.i = 0}},
    /* super ctrl up      |  移动窗口 */
    {MODKEY | ControlMask, XK_Up, movewin, {.ui = UP}},
    /* super ctrl down    |  移动窗口 */
    {MODKEY | ControlMask, XK_Down, movewin, {.ui = DOWN}},
    /* super ctrl left    |  移动窗口 */
    {MODKEY | ControlMask, XK_Left, movewin, {.ui = LEFT}},
    /* super ctrl right   |  移动窗口 */
    {MODKEY | ControlMask, XK_Right, movewin, {.ui = RIGHT}},
    /* super ctrl up      |  调整窗口 */
    {MODKEY | ControlMask, XK_k, resizewin, {.ui = V_REDUCE}},
    /* super ctrl down    |  调整窗口 */
    {MODKEY | ControlMask, XK_j, resizewin, {.ui = V_EXPAND}},
    /* super ctrl left    |  调整窗口 */
    {MODKEY | ControlMask, XK_h, resizewin, {.ui = H_REDUCE}},
    /* super ctrl right   |  调整窗口 */
    {MODKEY | ControlMask, XK_l, resizewin, {.ui = H_EXPAND}},

    /* spawn + SHCMD 执行对应命令(已下部分建议完全自己重新定义) */
    /* super enter      | 打开终端             */
    // {MODKEY, XK_Return, spawn, SHCMD("kitty")},
    {MODKEY, XK_Return, spawn, SHCMD("st")},
    // {MODKEY | ControlMask, XK_Return, spawn, SHCMD("kitty")},
    // /* super enter      | 打开浏览器           */
    {MODKEY, XK_c, spawn, SHCMD("google-chrome-stable")},
    // {MODKEY, XK_c, spawn, SHCMD("tabbed surf -e")},
    // { MODKEY,              XK_c,      spawn, SHCMD("Chromium") },
    /* super +          | 打开全局终端         */
    {MODKEY, XK_minus, spawn, SHCMD("st -c FG")},
    // st -c FG
    /* super space      | 打开浮动终端         */
    {MODKEY, XK_space, spawn, SHCMD("st -c float")},
    /* super d          | rofi: 执行命令         */
    {MODKEY, XK_p, spawn, SHCMD("rofi -show drun")},
    {MODKEY, XK_d, spawn, SHCMD("dmenu_run -fn 'JetBrainsMono Nerd Font' -p '   ' -nb '#181825' -nf '#adbac7' -sf '#181825' -sb '#7ec9d8'")},
    /* super F1         | 文件管理器             */
    {MODKEY, XK_F1, spawn, SHCMD("pcmanfm")},
    /* super k          | 锁定屏幕               */
    {MODKEY | ShiftMask, XK_k, spawn, SHCMD("blurlock")},
    /* super shift up   | 音量加                 */
    {MODKEY | ShiftMask, XK_Up, spawn, SHCMD("~/.scripts/set_vol.sh up")},
    /* super shift down | 音量减                 */
    {MODKEY | ShiftMask, XK_Down, spawn, SHCMD("~/.scripts/set_vol.sh down")},
    /* super shift a    | 截图                   */
    {0, XK_Insert, spawn, SHCMD("flameshot gui")},
    /* super chrl q    | 选中某个窗口并强制kill */
    {MODKEY | ControlMask, XK_q, spawn,
     SHCMD("kill -9 $(xprop | grep _NET_WM_PID | awk '{print $3}')")},
    /* super shift c    | 进阶复制               */
    {ShiftMask | ControlMask, XK_c, spawn,
     SHCMD("xclip -o | xclip -selection c")},

    /* super key : 跳转到对应tag (可附加一条命令 若目标目录无窗口，则执行该命令)
     */
    /* super shift key : 将聚焦窗口移动到对应tag */
    /* key tag cmd */
    TAGKEYS(XK_1, 0, 0)
    TAGKEYS(XK_2, 1, 0)
    TAGKEYS(XK_3, 2, 0)
    TAGKEYS(XK_4, 3, 0)
    TAGKEYS(XK_5, 4, 0)
    TAGKEYS(XK_6, 5, 0)
    TAGKEYS(XK_7, 6, 0)
    TAGKEYS(XK_8, 7, 0)
    TAGKEYS(XK_9, 8, 0)
};


static Button buttons[] = {
    /* click               event mask       button            function argument */
    // 左键        |  点击标题     |  隐藏其他窗口仅保留该窗口
    {ClkWinTitle, 0, Button1, hideotherwins, {0}},
    // 左键        |  点击状态栏   |  根据状态栏的信号执行
    // ~/scripts/dwmstatusbar.sh $signal L
    {ClkStatusText, 0, Button1, clickstatusbar, {0}},
    // 中键        |  点击状态栏   |  根据状态栏的信号执行
    // ~/scripts/dwmstatusbar.sh $signal M
    {ClkStatusText, 0, Button2, clickstatusbar, {0}},
    // 右键        |  点击状态栏   |  根据状态栏的信号执行
    // ~/scripts/dwmstatusbar.sh $signal R
    {ClkStatusText, 0, Button3, clickstatusbar, {0}},
    // 右键        |  点击标题     |  切换窗口显示状态
    {ClkWinTitle, 0, Button3, togglewin, {0}},
    // 左键        |  点击tag      |  切换tag
    {ClkTagBar, 0, Button1, view, {0}},
    // 右键        |  点击tag      |  切换是否显示tag
    {ClkTagBar, 0, Button3, toggleview, {0}},
    // super+左键  |  拖拽窗口     |  拖拽窗口
    {ClkClientWin, MODKEY, Button1, movemouse, {0}},
    // super+右键  |  拖拽窗口     |  改变窗口大小
    {ClkClientWin, MODKEY, Button3, resizemouse, {0}},
    // super+左键  |  点击tag      |  将窗口移动到对应tag
    {ClkTagBar, MODKEY, Button1, tag, {0}},
};
